/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.scm.struts.forms;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/**
 *
 * @author Sony
 */
public class StudentRegisterForm extends org.apache.struts.action.ActionForm {

    private String fname, mname, lname, gender, email, password, address, city, s_state, religion, s_cast, category, contact, enrollmentno;
    private int day, month, year,grno;
    private boolean physicallyhandicapped;

    public int getGrno() {
        return grno;
    }

    public void setGrno(int grno) {
        this.grno = grno;
    }

    public String getFname() {
        return fname;
    }

    public void setFname(String fname) {
        this.fname = fname;
    }

    public String getMname() {
        return mname;
    }

    public void setMname(String mname) {
        this.mname = mname;
    }

    public String getLname() {
        return lname;
    }

    public void setLname(String lname) {
        this.lname = lname;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getReligion() {
        return religion;
    }

    public void setReligion(String religion) {
        this.religion = religion;
    }

    public String getS_state() {
        return s_state;
    }

    public void setS_state(String s_state) {
        this.s_state = s_state;
    }

    public String getS_cast() {
        return s_cast;
    }

    public void setS_cast(String s_cast) {
        this.s_cast = s_cast;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getContact() {
        return contact;
    }

    public void setContact(String contact) {
        this.contact = contact;
    }

    public String getEnrollmentno() {
        return enrollmentno;
    }

    public void setEnrollmentno(String enrollmentno) {
        this.enrollmentno = enrollmentno;
    }

    public boolean getPhysicallyhandicapped() {
        return physicallyhandicapped;
    }

    public void setPhysicallyhandicapped(boolean physicallyhandicapped) {
        this.physicallyhandicapped = physicallyhandicapped;
    }

    public int getDay() {
        return day;
    }

    public void setDay(int day) {
        this.day = day;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    /**
     * @return
     */
    /**
     *
     */
    public StudentRegisterForm() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * This is the action called from the Struts framework.
     *
     * @param mapping The ActionMapping used to select this instance.
     * @param request The HTTP Request we are processing.
     * @return
     */
    @Override
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = new ActionErrors();
        //String  = ;
        Pattern enroll_regex = Pattern.compile("[0-9]{12}");
        Matcher enroll_matcher = enroll_regex.matcher(getEnrollmentno());
        
//        Pattern grno_regex = Pattern.compile("[0-9]{10}");
//        Matcher grno_matcher = grno_regex.matcher(getGrno());
        
        
        Pattern contact_regex = Pattern.compile("[7-9][0-9]{9}");
        Matcher contact_matcher = contact_regex.matcher(getContact());
        
        Pattern fname_regex = Pattern.compile("[a-z|A-Z| ]+");
        Matcher fname_matcher = fname_regex.matcher(getFname());
        
        if (getEnrollmentno() == null || getEnrollmentno().length() < 1) {
             
            errors.add("enrollno", new ActionMessage("student-register-error-enrollno-required"));
            // TODO: add 'error.name.required' key to your resources
        }
        if (!enroll_matcher.matches()) {
             errors.add("enrollno", new ActionMessage("student-register-error-enrollno-valid"));
        }
//        if (getGrno()== null || getGrno().length() < 1) {
//             
//            errors.add("grno", new ActionMessage("student-register-error-grno-required"));
//            // TODO: add 'error.name.required' key to your resources
//        }
//        if (!grno_matcher.matches()) {
//             errors.add("grno", new ActionMessage("student-register-error-grno-valid"));
//        }
        
        
        if (getFname() == null || getFname().length() < 1) {
            // System.out.println(" Error Avi bhai");
            errors.add("fname", new ActionMessage("student-register-error-fname-required"));
            // TODO: add 'error.name.required' key to your resources
        }
        if (!fname_matcher.matches()) {
             errors.add("fname", new ActionMessage("student-register-error-fname-valid"));
        }
        
        if (getMname() == null || getMname().length() < 1) {
            // System.out.println(" Error Avi bhai");
            errors.add("mname", new ActionMessage("student-register-error-mname-required"));
            // TODO: add 'error.name.required' key to your resources
        }
        if (getLname() == null || getLname().length() < 1) {
            // System.out.println(" Error Avi bhai");
            errors.add("lname", new ActionMessage("student-register-error-lname-required"));
            // TODO: add 'error.name.required' key to your resources
        }
        if (getGender() == null || getGender().length() < 1) {
            // System.out.println(" Error Avi bhai");
            errors.add("gender", new ActionMessage("student-register-error-gender-required"));
            // TODO: add 'error.name.required' key to your resources
        }
        if (getEmail() == null || getEmail().length() < 1) {
            // System.out.println(" Error Avi bhai");
            errors.add("email", new ActionMessage("student-register-error-email-required"));
            // TODO: add 'error.name.required' key to your resources
        }
//        if (!email_matcher.matches()) {
//             errors.add("email", new ActionMessage("student-register-error-email-valid"));
//        }
        
        if (getPassword() == null || getPassword().length() < 1) {
            // System.out.println(" Error Avi bhai");
            errors.add("password", new ActionMessage("student-register-error-password-required"));
            // TODO: add 'error.name.required' key to your resources
        }
        if (getAddress() == null || getAddress().length() < 1) {
            // System.out.println(" Error Avi bhai");
            errors.add("address", new ActionMessage("student-register-error-address-required"));
            // TODO: add 'error.name.required' key to your resources
        }
        if (getCity() == null || getCity().length() < 1) {
            // System.out.println(" Error Avi bhai");
            errors.add("city", new ActionMessage("student-register-error-city-required"));
            // TODO: add 'error.name.required' key to your resources
        }
        if (getReligion() == null || getReligion().length() < 1) {
            // System.out.println(" Error Avi bhai");
            errors.add("religion", new ActionMessage("student-register-error-religion-required"));
            // TODO: add 'error.name.required' key to your resources
        }
        if (getS_state() == null || getS_state().length() < 1) {
            // System.out.println(" Error Avi bhai");
            errors.add("state", new ActionMessage("student-register-error-state-required"));
            // TODO: add 'error.name.required' key to your resources
        }
        if (getS_cast() == null || getS_cast().length() < 1) {
            // System.out.println(" Error Avi bhai");
            errors.add("cast", new ActionMessage("student-register-error-cast-required"));
            // TODO: add 'error.name.required' key to your resources
        }
        
        if (getContact() == null || getContact().length() != 10) {
            // System.out.println(" Error Avi bhai");
            errors.add("contact", new ActionMessage("student-register-error-contact-required"));
            // TODO: add 'error.name.required' key to your resources
        }
          if (!contact_matcher.matches()) {
             errors.add("contact", new ActionMessage("student-register-error-contact-valid"));
        }
        return errors;
    }
}
